﻿using System;
using System.Configuration;
using Microsoft.Owin.Hosting;
using Sustainalytics.Insights.BusinessLogic;
using Sustainalytics.DataLayer;
using Sustainalytics.Utils;

namespace Sustainalytics.Insights.Service
{
    public static class ProgramConsole
    {
        private static AutoUnpublish updater;
        public static void Start()
        {
            try
            {
                using (var application = new InsightServiceApplication())
                {
                    application.Start();

                    updater = new AutoUnpublish(new InsightRepository(ConfigurationManager.ConnectionStrings["ClientPlatform"].ConnectionString));
                    WaitForExitCommand();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ExceptionUtility.GetInfo(ex, true));
                WaitForExitCommand();
            }


        }

        private static void WaitForExitCommand()
        {
            Console.WriteLine("Press X to exit.");
            while (true)
            {
                var key = Console.ReadKey(true);
                if (key.Key == ConsoleKey.X)
                {
                    break;
                }
            }
        }
    }
}
